package com.example.chengww.myone.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.chengww.myone.R;
import com.example.chengww.myone.bean.ReadADContent;

import java.util.List;

/**
 * Created by chengww on 2016/9/20.
 */
public class MyListAdapter extends BaseAdapter {

    private List<ReadADContent.Data> data;
    private Context context;

    public MyListAdapter(List<ReadADContent.Data> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public ReadADContent.Data getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.read_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.essay_author = (TextView) convertView.findViewById(R.id.essay_author);
            viewHolder.essay_guide_word = (TextView) convertView.findViewById(R.id.essay_guide_word);
            viewHolder.hp_title = (TextView) convertView.findViewById(R.id.hp_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.essay_author.setText(data.get(position).getAuthor());
        viewHolder.essay_guide_word.setText(data.get(position).getIntroduction());
        viewHolder.essay_guide_word.setMaxLines(2);
        int num = position + 1;
        String title = num+" "+data.get(position).getTitle();
        viewHolder.hp_title.setText(title);
        return convertView;
    }

    private class ViewHolder {
        private TextView essay_author;
        private TextView essay_guide_word;
        private TextView hp_title;
    }
}
